<?php
    $g4_path = "../"; 
    include($g4_path.'lib.php'); 
    require_once ($g4_path.'common.php');

    $datano = (int)$_POST['datano'];
    $type = strtolower($_POST['type']); 
    $value = addslashes($_POST['value']);
    $errormsg = NULL; 

    $sql = "UPDATE `course_order`";

    switch($type) {
        case 'input':
            $sql.= " SET memo='$value' ";
        break;

        case 'select':
            $sql.= " SET status='$value' ";
        break;
        default:
            $errormsg = "type이 지정되지 않았습니다.";
    }
    $sql.= "WHERE `no`='$datano' LIMIT 1";  
    $res = sql_query($sql); 
    if(!$res) {
        $errormsg.= mysql_error(); 
    }

    /**** 그룹에 학생 넣어주기 ****/
    if($value == '2') {
        $_res = sql_fetch("SELECT g.mb_id as teacherid FROM course_order co, course c, g4_member g WHERE co.no='$datano' AND co.course=c.no AND g.mb_no = c.teacher");
        $gr_id = 't_'.$_res['teacherid']; 
        $_res = sql_fetch("SELECT g.mb_id as studentid FROM course_order co, g4_member g WHERE co.no='$datano' AND g.mb_no = co.student");
        $mb_id = $_res['studentid']; 
        $sql = "REPLACE INTO g4_group_member (`gr_id`, `mb_id`, `gm_datetime`) VALUES ('$gr_id', '$mb_id', '".$g4['time_ymdhis']."')";
        sql_query($sql);
    /***** 그룹에 학생 넣기 끝 ****/

    }
    echo json_encode2(array('result'=>$res, 'errormsg'=>$errormsg)); 
